$(document).ready(function() {
  var agency = 'vicenza';
  var get = location.search.match(/operation=(\S+)/);
  var operation = get ? get[1] : null;
  $('.vote').on('click', function(event) {
    event.preventDefault();
    $.ajax('http://atcustomer.servehttp.com:8888/' + agency, {
      type : 'POST',
      contentType : 'application/json',
      processData : false,
      data : JSON.stringify({
        "agency" : agency,
        "operation" : operation,
        "score" : $(this).data('score'),
        "date" : new Date(),
        "comment" : $('#comment').val(),
        "customerName" : $('#customerName').val(),
        "email" : $('#email').val()
      })
    }).then(function(event) {
      $('#feedback').modal({
        backdrop : 'static'
      });
    });
  });
  $('#feedback').on('shown', function(event) {
    setTimeout(function() {
      $(event.target).modal('hide');
    }, 3000);
  });
  $('#feedback').on('hidden', function(event) {
    location.href = 'intro';
  });
  $('#comment-placeholder').on('focus', function(event) {
    $(event.target).blur();
    $('#modalComment').modal({
      backdrop : 'static'
    });
  });
  $('#privacy').on('click', function(event) {
    if ($('#privacy').attr("checked")) {
      $('.invia').removeAttr('disabled');
    } else {
      $('.invia').attr('disabled', 'true');
    }
  });
  $('#sendComment').on('click', function(event) {
    $('#comment-placeholder').val($('#comment').val());
  });
});